package com.aquarium.bt;

import com.aquarium.R;
import com.aquarium.module.ModuleControlService;
import com.aquarium.ui.AlarmService;
import com.aquarium.ui.SensorValueDisplayActivity;
import com.aquarium.ui.WelcomeActivity;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.ContextThemeWrapper;

public class DisconnectReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		if (intent.getAction().equals(BTManager.DISCONNECTION_ACTION)) {

			final Context mContext = context;

			AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
			builder.setMessage(mContext.getString(R.string.exit_confirm))
					.setPositiveButton(mContext.getText(R.string.ok),
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {

									Intent intent2 = new Intent();
									intent2.setClass(mContext,
											WelcomeActivity.class);
									mContext.startActivity(intent2);

								}
							})
					.setNegativeButton(context.getText(R.string.leave),
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {

									// mBTManager.close();
									mContext.stopService(new Intent(mContext
											.getApplicationContext(),
											AlarmService.class));
									mContext.stopService(new Intent(mContext
											.getApplicationContext(),
											ModuleControlService.class));
									System.exit(0);
								}
							});
			builder.create().show();

		}
	}
}
